package io.persimmon.core.module.id.instance;

import io.persimmon.core.module.id.IdFactory;
import io.persimmon.core.module.id.bo.BatchId;
import io.persimmon.core.module.id.bo.ListBatchId;
import io.persimmon.core.module.id.bo.SnowFlakeId;

import java.util.ArrayList;
import java.util.List;

public class SnowFlakeIdFactory implements IdFactory<Long> {
    private SnowFlakeId snowflakeId = new SnowFlakeId();

    @Override
    public Long createId() {
        return this.snowflakeId.createLongId();
    }

    @Override
    public BatchId<Long> batchCreateId(int Long) {
        return new ListBatchId<Long>(Long) {
            @Override
            public List<Long> batchCreateId(int batchSize) {
                List<Long> list = new ArrayList<>(batchSize);
                for (int i = 0; i < batchSize; i++) {
                    list.add(createId());
                }
                return list;
            }
        };
    }
}
